﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BuyNets_2 : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            tbUserName.Text = _User.Name;

            BindData();

            btnBuy.Attributes.Add("onclick", "return confirm('" + System.Web.HttpUtility.HtmlEncode("您确信要购分红网点位吗？") + "');");
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        SecondLevelPassword = true;
        RequestLoginPage = "BalanceCenter/BuyNets_2.aspx";

        base.OnInit(e);
    }

    #endregion

    private void BindData()
    {        
        //int NumLimit = 0;
        //switch (_User.UserType)
        //{
        //    case 1:
        //        NumLimit = ShoveEL._Convert.StrToInt(PublicFunction.GetOptions("1级购买分红网点位个数限制"), 1);
        //        break;
        //    case 2:
        //        NumLimit = ShoveEL._Convert.StrToInt(PublicFunction.GetOptions("2级购买分红网点位个数限制"), 2);
        //        break;
        //    case 3:
        //        NumLimit = ShoveEL._Convert.StrToInt(PublicFunction.GetOptions("3级购买分红网点位个数限制"), 3);
        //        break;
        //    case 4:
        //        NumLimit = ShoveEL._Convert.StrToInt(PublicFunction.GetOptions("4级购买分红网点位个数限制"), 4);
        //        break;
        //}

        double Price = ShoveEL._Convert.StrToDouble(PublicFunction.GetOptions("累积重复消费多少进入分红网").ToString(), 360);

        string Return = "";
        int Result = _User.GetUserInfoByID(ref Return);

        if (_User.VirtualMoney + _User.FundManage < Price)
        {
            labTip.Text = "帐户电子货币及重复消费基金余额不足。";
            btnBuy.Enabled = false;
            return;
        }
        else
        {
            labTip.Text = "允许购买。";
        }

    //    if (_User.FundManageDistillUserSelf >= NumLimit)
    //    {
    //        labTip.Text = "您最多可以购买 " + NumLimit + " 个点位，您已经购买了 " + _User.FundManageDistillUserSelf.ToString() + " 个。";
    //        btnBuy.Enabled = false;
    //        return;
    //    }

    //    labTip.Text = "您最多可以购买 " + NumLimit + " 个点位，您已经购买了 " + _User.FundManageDistillUserSelf.ToString() + " 个。";
    }

    protected void btnBuy_Click(object sender, EventArgs e)
    {
        int Result = 0;
        string Return = "";

        try
        {
            DAL.Procedures.P_BuyForNets_2_UserSelf.Call(_User.ID,ref Result,ref Return);
        }
        catch { }

        if (Result != 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page,Return);
            return;
        }

        Panel1.Visible = false;
        Panel2.Visible = true;
    }
}
